package com.ewhale.feitengguest.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.ewhale.feitengguest.R;
import com.simga.library.activity.MBaseActivity;
import com.simga.library.utils.CheckUtil;
import com.simga.library.utils.KeyBoardUtils;
import com.simga.library.widget.BGButton;

import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InputNameDialog extends Dialog {


    @BindView(R.id.et_name)
    EditText mEtName;
    @BindView(R.id.btn_commit)
    BGButton mBtnCommit;
    @BindView(R.id.iv_close)
    ImageView mIvClose;

    private MBaseActivity mActivity;
    private String hint;

    public InputNameDialog(@NonNull Context context, String hint) {
        super(context, com.simga.library.R.style.Dialog);
        this.setCanceledOnTouchOutside(false);
        setContentView(R.layout.dialog_input);
        ButterKnife.bind(this);
        this.hint = hint;
        mActivity = (MBaseActivity) context;
        mEtName.setHint(hint);
        setOnShowListener(new OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                KeyBoardUtils.showSoftInputFromWindow(mActivity, mEtName);
            }
        });
    }

    @OnClick({R.id.btn_commit, R.id.iv_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_commit:
                if (CheckUtil.isNull(mEtName.getText().toString())) {
                    mActivity.showToast("请输入" + hint);
                    return;
                }
                if (mCommitCallBack != null) {
                    mCommitCallBack.onCallBack(mEtName.getText().toString());
                }
                break;
            case R.id.iv_close:
                break;
        }
        KeyBoardUtils.closeKeybord(mActivity, mEtName);
        dismiss();
    }

    private onCommitCallBack mCommitCallBack;

    public void setCommitCallBack(onCommitCallBack commitCallBack) {
        mCommitCallBack = commitCallBack;
    }

    public interface onCommitCallBack {
        void onCallBack(String name);
    }
}
